package com.qk.management.controller;

import com.qk.common.Result;

import com.qk.common.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /**
     * 文件上传
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws Exception {
        log.info("文件上传开始：{}", image.getOriginalFilename());
        //获取原始文件后缀名

        //生成新的文件名

        String url = aliyunOSSOperator.upload(image.getBytes(), (UUID.randomUUID() + image.getOriginalFilename().substring(image.getOriginalFilename().lastIndexOf("."))));
        return Result.success(url);
    }

}